<?php
/**
 * Created by PhpStorm.
 * User: chenzhenlin
 * Date: 2019/3/29
 * Time: 1:40 AM
 */

namespace app\api\traits;


use app\common\helpers\Functions;

trait VisitRecord
{


    /**
     * 格式化
     * @param $value
     * @return mixed
     */
    public static function format($value){
        if(isset($value['create_time'])) $value['create_time'] = $value['create_time'] ? Functions::formatDateTime($value['create_time']) : '';
        if(isset($value['update_time'])) $value['update_time'] = $value['update_time'] ? Functions::formatDateTime($value['update_time']) : '';

        return $value;
    }

    /**
     * 格式化 info
     * @param $info
     */
    public static function formatInfo($info){
        if(!empty($info)){
            $info = self::format($info);
        }
        return $info;
    }

    /**
     * 格式化 list
     * @param $list
     * @return mixed
     */
    public static function formatList($list){
        if(!empty($list)){
            foreach ($list as $key => &$value){
                $value = self::format($value);
            }
        }
        return $list;
    }
}